home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime vr / vrscript / common files / winframework.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  8.2 KB  |  236 lines

  1. //////////
  2. //
  3. //    File:        WinFramework.h
  4. //
  5. //    Contains:    Basic functions for windows, menus, and similar things.
  6. //
  7. //    Written by:    Tim Monroe
  8. //                Based on MDIPlayer sample code by Brian S. Friedkin (Aug 5, 1996).
  9. //
  10. //    Copyright:    © 1996-1998 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //    Change History (most recent first):
  13. //
  14. //       <2>         11/02/98    rtm        minor reworking to coordinate with MacFramework.h
  15. //       <1>         07/03/96    rtm        first file; revised to personal coding style;
  16. //                                    renamed numerous types and parameters to mirror QTShell on MacOS
  17. //       
  18. //////////
  19.  
  20. #pragma once
  21.  
  22. // header files
  23.  
  24. #ifndef __Prefix_File__
  25. #include <WinPrefix.h>
  26. #endif
  27.  
  28. #include <windows.h>
  29.  
  30. #ifndef __FIXMATH__
  31. #include <FixMath.h>
  32. #endif
  33.  
  34. #ifndef __MOVIES__
  35. #include <Movies.h>
  36. #endif
  37.  
  38. #ifndef __RESOURCES__
  39. #include <Resources.h>
  40. #endif
  41.  
  42. #ifndef __QTML__
  43. #include <QTML.h>
  44. #endif
  45.  
  46. #ifndef __QUICKTIMEVR__
  47. #include <QuickTimeVR.h>
  48. #endif
  49.  
  50. #ifndef __SCRAP__
  51. #include <Scrap.h>
  52. #endif
  53.  
  54. #ifndef __SOUND__
  55. #include <Sound.h>
  56. #endif
  57.  
  58. #ifndef __TEXTUTILS__
  59. #include <TextUtils.h>
  60. #endif
  61.  
  62. #ifndef __QTUtilities__
  63. #include "QTUtilities.h"
  64. #endif
  65.  
  66.  
  67. //////////
  68. //
  69. // constants
  70. //
  71. //////////
  72.  
  73. #define    WM_PUMPMOVIE                (WM_USER+0)
  74. #define    WM_OPENDROPPEDFILES            (WM_USER+1)
  75. #define USEEXPLORERSTYLE            (LOBYTE(LOWORD(GetVersion()))>=4)
  76. #define kOpenDialogCustomData        11                        // an arbitrary value that allows our dialog proc to detect the Open File dialog box
  77. #define kAlertMessageMaxLength        256                        // maximum length of a message in the DoCautionAlert message box
  78.  
  79. #define kNewMovieName                "C:\\untitled.mov"        // default name of a movie created by "New" menu command
  80.  
  81. #define kInvalidFileRefNum            -1                        // an invalid file reference number
  82.  
  83. #define kWinFilePathSeparator        (char)'\\'                // on Windows, the file path separator is '\\'
  84.  
  85. // items in Save Changes dialog box
  86. #define kSaveChanges                IDYES                    // save the changes before closing window
  87. #define kCancelClose                IDCANCEL                // no, don't close the window or save changes
  88. #define kDontSaveChanges            IDNO                    // discard any unsaved changes
  89.  
  90. // constants for standard modal dialog filter proc
  91. #define kMyButtonDelay                8
  92. #define kReturnKey                    (char)0x0D    
  93. #define kEnterKey                    (char)0x03    
  94. #define kEscapeKey                    (char)0x1B    
  95. #define kPeriod                        '.'
  96.  
  97. // constants for selecting InitApplication phase
  98. enum {
  99.     kInitAppPhase_BeforeCreateFrameWindow     = 1L << 0,        // MDI frame window windows not yet created
  100.     kInitAppPhase_AfterCreateFrameWindow    = 1L << 1,        // MDI frame window windows already created
  101.     kInitAppPhase_BothPhases                = kInitAppPhase_BeforeCreateFrameWindow | kInitAppPhase_AfterCreateFrameWindow
  102. };
  103.  
  104. // constants for selecting StopApplication phase
  105. enum {
  106.     kStopAppPhase_BeforeDestroyWindows         = 1 << 0,        // movie windows not yet torn down
  107.     kStopAppPhase_AfterDestroyWindows        = 1    << 1,        // movie windows already torn down
  108.     kStopAppPhase_BothPhases                = kStopAppPhase_BeforeDestroyWindows | kStopAppPhase_AfterDestroyWindows
  109. };
  110.  
  111. // parameters to the SetMenuItemState function
  112. #define kEnableMenuItem                MF_ENABLED
  113. #define kDisableMenuItem            MF_GRAYED
  114.  
  115. enum {
  116.     kMovieControllerObject          = FOUR_CHAR_CODE('MCvr')
  117. };
  118.  
  119.  
  120. //////////
  121. //
  122. // macros
  123. //
  124. //////////
  125.  
  126. // macros for converting Mac menu ID/menu item pairs into a single "menu item identifier"
  127. #define MENU_IDENTIFIER(menuID,menuItem)    ((menuID<<8)+(menuItem))
  128. #define MENU_ID(menuIdentifier)                ((menuIdentifier&0xff00)>>8)
  129. #define MENU_ITEM(menuIdentifier)            ((menuIdentifier&0x00ff))
  130.  
  131.  
  132. //////////
  133. //
  134. // data types
  135. //
  136. //////////
  137.  
  138. typedef HMENU                MenuReference;
  139. typedef HWND                WindowReference;
  140.  
  141.  
  142. //////////
  143. //
  144. // structures
  145. //
  146. //////////
  147.  
  148. // WindowObjectRecord is a data structure attached to a movie window.
  149. // We use this structure to associate data with any window presented.
  150.  
  151. typedef struct {
  152.     WindowReference            fWindow;            // the window
  153.     OSType                    fObjectType;        // specific tag indicating that the window object belongs to our application
  154.     Movie                    fMovie;                // the main movie (QT or QTVR)
  155.     MovieController         fController;        // the movie controller for this window
  156.     FSSpec                    fFileFSSpec;        // location of the movie file
  157.     short                    fFileResID;
  158.     short                    fFileRefNum;
  159.     Boolean                    fCanResizeWindow;    // can the window be resized?
  160.     Boolean                    fDirty;                // has the movie data changed since the last save?
  161.     QTVRInstance            fInstance;            // the QTVRInstance
  162.     Handle                    fAppData;            // a handle to application-specific window data
  163. } WindowObjectRecord, *WindowObjectPtr, **WindowObject;
  164.  
  165.  
  166. //////////
  167. //
  168. // function prototypes
  169. //       
  170. //////////
  171.  
  172. LRESULT CALLBACK             FrameWndProc (HWND theWnd, UINT theMessage, UINT wParam, LONG lParam);
  173. LRESULT CALLBACK             MovieWndProc (HWND theWnd, UINT theMessage, UINT wParam, LONG lParam);
  174. BOOL                        GetFile (char *theFileName);
  175. int                            AdjustMenus (HWND theWnd, HMENU theMenu);
  176. void                        QuitFramework (void);
  177.  
  178. Boolean                     DoCreateNewMovie (void);
  179. MovieController                SetupMovieWindowWithController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow);
  180. void                        DoOpenCommandLineMovies (LPSTR theCmdLine);
  181. BOOL                        DoCreateMovieWindow (Movie theMovie, FSSpec *theFSSpec);
  182. OSErr                        DoSaveAsMovieFile (WindowReference theWindow);
  183. Boolean                        DoUpdateMovieFile (WindowReference theWindow);
  184. static void                    DoCut (HWND theWnd);
  185. static void                    DoCopy (HWND theWnd);
  186. static void                    DoPaste (HWND theWnd);
  187. static void                    DoClear (HWND theWnd);
  188. static void                    DoUndo (HWND theWnd);
  189. static void                    GetDisplayName (char *thePathName, char *theFileName);
  190.  
  191. void                        SizeWindowToMovie (WindowObject theWindowObject);
  192. static void                    ShowAboutBox (void);
  193. int                            DoCautionAlert (HWND theWnd, UINT theID, UINT theIconStyle, UINT theButtonStyle, LPSTR theTitle, LPSTR theArgument);
  194. static UINT APIENTRY        DialogProc (HWND theDialog, UINT theMessage, WPARAM wParam, LPARAM lParam);
  195. static void                    CalcWindowMinMaxInfo (HWND theWnd, LPMINMAXINFO lpMinMax);
  196. static void                    SetWindowTitleFromFSSpec (HWND theWnd, FSSpec *theFSSpec, Boolean theAddToRecentDocs);
  197.  
  198. WindowReference                GetFrontMovieWindow (void);
  199. WindowReference                GetNextMovieWindow (WindowReference theWindow);
  200. WindowObject                GetWindowObjectFromFrontWindow (void);
  201. WindowObject                GetWindowObjectFromWindow (WindowReference theWnd);
  202. MovieController              GetMCFromFrontWindow (void);
  203. MovieController                GetMCFromWindow (WindowReference theWindow);
  204. QTVRInstance                GetQTVRInstanceFromFrontWindow (void);
  205. Handle                        GetAppDataFromFrontWindow (void);
  206. Handle                        GetAppDataFromWindow (WindowReference theWnd);
  207. Handle                        GetAppDataFromWindowObject (WindowObject theWindowObject);
  208. Boolean                     IsWindowObjectOurs (WindowObject theWindowObject);
  209. void                        DoBeep (void);
  210. void                        SetMenuState (MenuReference theMenu, UInt16 theMenuRank, short theState);
  211. void                        SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState);
  212. void                        SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText);
  213. void                        SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState);
  214. GrafPtr                        GetPortFromWindowReference (WindowReference theWindow);
  215. WindowReference                GetWindowReferenceFromPort (GrafPtr thePort);
  216. short                        GetWindowWidth (WindowReference theWindow);
  217. WindowReference                GetFrontAppWindow (void);
  218. WindowReference                GetNextAppWindow (WindowReference theWindow);
  219.  
  220.  
  221. // application-specific functions
  222. // These are defined in the ComApplication.c file;
  223. // you could override these to change the behavior of the function in a specific application.
  224. void                        InitApplication (UInt32 theStartPhase);
  225. void                        StopApplication (UInt32 theStopPhase);
  226. void                        DoIdle (WindowReference theWindow);
  227. void                        DoUpdateWindow (WindowReference theWindow, Rect *theRefrehArea);
  228. void                         HandleContentClick (WindowReference theWindow, EventRecord *theEvent);
  229. Boolean                        HandleApplicationKeyPress (char theCharCode);
  230. void                         HandleApplicationMenu (UInt16 theMenuItem);
  231. void                        AdjustApplicationMenus (WindowReference theWindow, MenuReference theMenu);
  232. Boolean                        DoApplicationEventLoopAction (EventRecord *theEvent);
  233. void                        AddControllerFunctionality (MovieController theMC);
  234. void                        InitApplicationWindowObject (WindowObject theWindowObject);
  235. void                        RemoveApplicationWindowObject (WindowObject theWindowObject);
  236. PASCAL_RTN Boolean             ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon);